package com.ctl.szmd.szmd.feature_wm.ui.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import com.ctl.szmd.szmd.feature_wm.data.model.WmDataListModel
import com.ctl.szmd.szmd.feature_wm.data.repository.WmRepository
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.launch

/**
 * created by : chentl
 * Date: 2020/07/28
 */
class WmHomeViewModel(private val repository: WmRepository) :
    ViewModel() {
    var mBannerListData = MutableLiveData<List<WmDataListModel>>()


    fun getInfoFacePartyListData() =
        liveData<PagingData<WmDataListModel>> {
            repository.getInfoFacePartyListData()
                .onStart {
                }
                .catch {
                }
                .onCompletion {
                }
                .collectLatest {
                    emit(it)
                }
        }

    @ExperimentalCoroutinesApi
    fun getInfoWomenHeadlineListData() = viewModelScope.launch {
        repository.getInfoWomenHeadlineListData()
            .onStart {
            }
            .catch {
            }
            .onCompletion {
            }
            .collectLatest {
                mBannerListData.postValue(it)
            }
    }
}